package logic

import (
	"context"
	"shop/shoprpc/shoprpc"

	"shop/api/internal/svc"
	"shop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopAddLogic) ShopAdd(req *types.ShopAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	shopadd, err := l.svcCtx.ShopRpc.ShopAdd(l.ctx, &shoprpc.ShopAddRequest{
		Shopname:  req.Shopname,
		Shopimage: req.Shopimage,
		Price:     req.Price,
		Stock:     req.Stock,
		Userid:    req.Userid,
	})
	if err != nil {
		return &types.Response{
			Code:    0,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品添加成功",
		Data:    shopadd,
	}, nil

}
